<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { gamesApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import xmDatePicker from '@/components/xmDatePicker/index.vue';
  import serachUserid from '@/components/serachUserid/index.vue';
  import Pagination from "@/components/Pagination/index.vue";
  const action = reactive({
    total:0,
    list:[] as any[],
    timeObj:getPlayEndTime(getDateArray('ymdhis')),
  })
  const initialQuery = {
    page:1,
    limit:20,
    user_id:'',
  }
  const listQuery = reactive({
    ...initialQuery
  })
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      ...initialQuery
    })
    getList()
  }
  const handleSerach = ()=>{
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const { playTime:date_st, endTime:date_ed } = action.timeObj
    const res = await gamesApi.redPacketRainLogList({
      ...listQuery,
      date_st,
      date_ed
    })
    loading.close()
    const { data=[], total=0 } = res.data
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <xmDatePicker v-model:timeval="action.timeObj" />
      </div>
      <div class="labelBox">
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="100" prop="id" label="记录ID" />
      <el-table-column width="100" prop="rain_id" label="红包雨ID" />
      <el-table-column width="100" prop="diamond_num" label="红包钻石数" />
      <el-table-column width="100" prop="uuid" label="用户UUID" />
      <el-table-column width="100" prop="user_id" label="用户ID" />
      <el-table-column min-width="180" show-overflow-tooltip prop="nickname" label="用户昵称" />
      <el-table-column width="180" prop="user_union_id" label="用户公会ID" />
      <el-table-column width="180"  show-overflow-tooltip prop="user_union_name" label="用户公会名称" />
      <el-table-column width="120" prop="room_id" label="房间ID" />
      <el-table-column width="180"  show-overflow-tooltip prop="room_name" label="房间名称" />
      <el-table-column width="120" prop="room_union_id" label="房间归属公会ID" />
      <el-table-column width="180"  show-overflow-tooltip prop="room_union_name" label="房间归属公会名称" />
      <el-table-column width="180" prop="created_at" label="创建时间" />
      <el-table-column width="180" prop="start_time" label="红包雨开始时间" />
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>